﻿<template>
    <div>
        <h2>学校名称:{{name}}</h2>
        <h2>学校地址:{{address}}</h2>
        <h2 v-cloak>接收到的学生姓名:{{sName}}</h2>
    </div>
</template>

<script>
    import pubsub from 'pubsub-js'

    export default{
        name:'School',
        components:{},
        data() {
            return {
                name: 'bilibili',
                address:'魔都',
                sName:''
            }
        },
        mounted() {
            this.pubId = pubsub.subscribe('hello',(msgName,data)=>{
                console.log(this)
                console.log('有人发布了hello消息,hello消息的回调函数被执行了',msgName,data)
                this.sName = data
            })
        },
        beforeDestroy() {
            pubsub.unsubscribe(this.pubId)
        },
    }
</script>

<style>
    [v-cloak]{
        display: none;
    }
</style>